package br.com.cnpv.modelo.bo;

import java.util.List;

import org.hibernate.Session;

import br.com.cnpv.modelo.acesso.idao.IMarcaDAO;
import br.com.cnpv.modelo.dao.MarcaDAO;
import br.com.cnpv.modelo.entity.Marca;
import br.com.cnpv.util.HibernateUtil;

public class MarcaBO extends HibernateUtil
{
	public static MarcaBO INSTANCE;
	
	public static MarcaBO getInstance()
	{
		if(INSTANCE == null)
		{
			synchronized (MarcaBO.class) {
				INSTANCE = new MarcaBO();
			}
		}
		return INSTANCE;
	}

	public List<Marca> listar() throws Exception
	{
		Session session = null;
		List<Marca> list = null;
		
		try
		{
			session = currentSession();
			IMarcaDAO dao = new MarcaDAO();
			list = dao.listar(session);
		}catch(Exception e)
		{
			throw new Exception(e);
		}finally
		{
			if(session != null)
			{
				session.flush();
				session.clear();
			}
			closeSession();
		}
		return list;
	}

	public List<Marca> listarPorTipo(Integer idTipoVeiculo) throws Exception
	{
		Session session = null;
		List<Marca> list = null;
		
		try
		{
			session = currentSession();
			IMarcaDAO dao = new MarcaDAO();
			list = dao.listarPorTipo(idTipoVeiculo, session);
		}catch(Exception e)
		{
			throw new Exception(e);
		}finally
		{
			if(session != null)
			{
				session.flush();
				session.clear();
			}
			closeSession();
		}
		return list;
	}
}
